//
//  LBCategoryModel.m
//  jslj
//
//  Created by luckyRoy on 2017/10/10.
//  Copyright © 2017年 广东联结电子商务有限公司. All rights reserved.
//

#import "LBCategoryModel.h"
#import <MJExtension.h>

@implementation LBCategoryModel

- (id)copyWithZone:(NSZone *)zone
{
    LBCategoryModel *model = [[LBCategoryModel allocWithZone:zone] init];
    model.name = self.name;
    model.code  = self.code;
    model.isSelected = self.isSelected;
    model.parCode = self.parCode;
    model.parName = self.parName;
    model.parLogo = self.parLogo;
    model.viewType = self.viewType;
    model.isAll = self.isAll;
    return model;
}

+ (void)initialize
{
    [LBCategoryModel mj_setupObjectClassInArray:^NSDictionary *{
        return @{
                 @"chirdrenNode" : @"LBCategoryModel"
                 };
    }];
}

- (NSString *)namePingYin
{
    if (!_namePingYin) {
        _namePingYin = [self getPinYin:self.name];
    }
    return _namePingYin;
}

//获取汉字拼音(传入汉字字符串, 返回小写拼音)
- (NSString *)getPinYin:(NSString *)aString
{
    //转成了可变字符串
    NSMutableString *str = [NSMutableString stringWithString:aString];
    //先转换为带声调的拼音
    CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformMandarinLatin,NO);
    //再转换为不带声调的拼音
    CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformStripDiacritics,NO);
    //转化为大写拼音
    NSString *pinYin = [str lowercaseString];
    
    //获取并返回，过滤所有空格符号
    return [pinYin stringByReplacingOccurrencesOfString:@" " withString:@""];
}

@end
